package com.zhongjian.technologycal.mall.utils;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhongjian.technologycal.mall.R;

import butterknife.BindView;

/**
 * Created by wei on 2018/1/26.
 */

public class CommonDialog1 {

    private Dialog dialog;
    Context context;
    DialogPositiveListener positiveListener;
    DialogNegativeListener negativeListener;

    public CommonDialog1(Context context) {
        super();
        this.context = context;
    }

    public void setPositiveListener(DialogPositiveListener positiveListener) {
        this.positiveListener = positiveListener;
    }

    public void setNegativeListener(DialogNegativeListener negativeListener) {
        this.negativeListener = negativeListener;
    }

    /**
     * context promptMsg 提示信息
     */
    public Dialog initDialog(String promptMsg) {
        return initDialog(promptMsg, "取消", "确认");
    }

    /**
     * context promptMsg 提示信息 cancleBtnMsg 取消按钮信息 sureBtnMsg 确认按钮信息
     */
    public Dialog initDialog(String money, String cancleBtnMsg, String sureBtnMsg) {
        View view = LayoutInflater.from(context).inflate(
                R.layout.pwindow_dialog_red, null);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        dialog = ResultDialog.creatAlertDialog(context,view);
        Window window = dialog.getWindow();
        window.setGravity(Gravity.CENTER);  //此处可以设置dialog显示的位置
//        window.setWindowAnimations(R.style.mystyle);
        window.setWindowAnimations(R.style.popupWindowAnimation10);

        ImageView imageView_redpacket = view.findViewById(R.id.imageView_redpacket);
        TextView  redPacket_tv_money = view.findViewById(R.id.redPacket_tv_money);

        redPacket_tv_money.setText(cancleBtnMsg);
        imageView_redpacket.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (negativeListener != null) {
                    negativeListener.onClick();
                }
            }
        });

//        btnSure.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (positiveListener != null) {
//                    positiveListener.onClick();
//                }
//                dialog.dismiss();
//            }
//        });

        return dialog;
    }

    public interface DialogPositiveListener {
        void onClick();
    }

    public interface DialogNegativeListener {
        void onClick();
    }


}
